package com.salton123.soulove.api

import android.content.Context
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.alibaba.android.arouter.launcher.ARouter
import com.salton123.soulove.common.Constants
import com.salton123.util.FragmentUtils

/**
 * Time:6/26/21 7:02 PM
 * Author:
 * Description:
 */
object RouterManager {
    private fun String.buildPage(context: Context): Fragment {
        return ARouter.getInstance()
            .build(this)
            .navigation(context) as Fragment
    }

    private fun String.goPage(context: Context) {
        ARouter.getInstance().build(this).navigation(context)
    }

    fun videoPlay(context: Context, index: Int) {
        ARouter.getInstance().build(Constants.Router.Video.PLAY)
            .withInt("index", index)
            .navigation(context)
    }

    fun videoCompress(context: Context, filePath: String) {
        ARouter.getInstance().build(Constants.Router.Video.COMPRESS)
            .withString("filePath", filePath)
            .navigation(context)
    }

    fun searchVideo(context: Context) {
        ARouter.getInstance().build(Constants.Router.Video.SEARCH)
            .navigation(context)
    }

    fun setting(context: Context) {
        ARouter.getInstance().build(Constants.Router.User.SETTING)
            .navigation(context)
    }

    fun batchOperate(context: Context, dirName: String) {
        ARouter.getInstance().build(Constants.Router.Video.BATCH)
            .withString("dirName", dirName)
            .navigation(context)
    }

    fun about(context: Context) {
        Constants.Router.User.ABOUT.goPage(context)
    }

    fun policy(context: Context) {
        Constants.Router.User.POLICY.goPage(context)
    }

    fun termOfService(context: Context, title: String, url: String) {
        ARouter.getInstance().build(Constants.Router.User.POLICY)
            .withString("title", title)
            .withString("url", url)
            .navigation(context)
    }

    fun rateUs(context: FragmentActivity) {
        val comp = Constants.Router.Video.RATE_US.buildPage(context) as DialogFragment
        FragmentUtils.showDialogFragment(context.supportFragmentManager, comp, "RateUsPopupComp")
    }
}